<?php
require_once("../../../class2.php");
require_once("../library/admin/adminapi.php");

if(!getperms("P")){header("location:".e_BASE."index.php"); exit; }
require_once(e_ADMIN."auth.php");

// Include userclass_class.php which is necessary for function r_userclass (dropdown of classes)
require_once(e_HANDLER."userclass_class.php");

// Check if one of the gateways should be (de-)activated
if($_GET["a"]=='0') {
    $update = e107shop_activate_gateway($_GET["g"], 0);
}

if($_GET["a"]=='1') {
    $update = e107shop_activate_gateway($_GET["g"], 1);
}

if ($update === true) $ns->tablerender("<center>".lan_global_status."</center>", "<center><span style='background-color: #00FF21;'>".lan_global_updated."</span></center>");
if ($update === false) $ns->tablerender("<center>".lan_global_status."</center>", "<center><span style='background-color: #FF0000;'>".lan_global_error."</span></center>");


//
// If the form has been submitted
//
if($_POST["subbed"]) {
    e107shop_process_gateway_update($_POST["g"], $_POST["gateway_account"], $_POST["field1"], 
    $_POST["field2"], $_POST["field3"], $_POST["field4"], $_POST["field5"], $_POST["field6"], 
    $_POST["field7"], $_POST["field8"], $_POST["gateway_class"]);
}

$sql = new db;
$sql->db_Select($e107shop_db_name["gateways"], "*", "");
$gatewaylist = '';
while ($row=$sql->db_Fetch(MYSQL_ASSOC)) {
    $gatewaylist[] = $row;
}

//
// list gateways
//
$display="<br /><table class='fborder'>
        <tr><td class='forumheader' style='width: 100px;'>".lan_admin_manage_gateways_col1."</td>
        <td class='forumheader'>".lan_admin_manage_gateways_col2."</td>
        <td class='forumheader'>".lan_admin_manage_gateways_col3."</td>
        <td class='forumheader'>".lan_admin_gateway_class."</td>
        </tr>";


foreach ($gatewaylist as $gatewayrecord) 
{
    foreach ($gatewayrecord as $key => $value) 
    {
        if ($key == 'identifier') $gateway_file = $value;
        if ($key == 'gateway_class') $gateway_class = $value;
        if ($key == 'active') 
        {
            if ($value == 0) 
            {
                $gwaction = lan_admin_manage_gateways_activate;
                $activate = 1;
                $color = '#FF0000';
            }
            else 
            {
                $gwaction = lan_admin_manage_gateways_deactivate;
                $activate = 0;
                $color = '#00FF21';
            }
            $display .= "<tr><td class='forumheader2' style='background-color: ".$color.";'>".$gateway_file."</td>
                    <td class='forumheader2'><a href='".e_SELF."?a=".$activate."&g="
                    .$gateway_file."'>".$gwaction."</a></td>
                    <td class='forumheader2'><a href='".e_SELF."?a=2&g="
                    .$gateway_file."'>".lan_admin_manage_gateways_edit."</a></td>
                    <td class='forumheader2'>".r_userclass_name($gateway_class)."</td>
                    </tr>";    
        }
    }
}
$display.="</table>";

$ns->tablerender("<center>".lan_admin_menu_gateway."</center>", $display);

if($_GET["a"]==2) {
    $display = "<form action='".e_SELF."' method='POST'><br />
                <table class='fborder' width='95%' border='0'>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_account."</td>
                    <td class='forumheader3'>
                    <input class='tbox' type='text' name='gateway_account' value='"
                    .e107shop_get_gateway($_GET["g"], "account")."'></td>
                </tr>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_url."</td>
                    <td class='forumheader3'><input class='tbox' type='text' name='field1' value='"
                    .e107shop_get_gateway($_GET["g"], "field1")."'></td>
                </tr>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_key."</td>
                    <td class='forumheader3'><input class='tbox' type='text' name='field2' value='"
                    .e107shop_get_gateway($_GET["g"], "field2")."'></td>
                </tr>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_charge."</td>
                    <td class='forumheader3'><input class='tbox' type='text' name='field3' value='"
                    .e107shop_get_gateway($_GET["g"], "field3")."'></td>
                </tr>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_amount."</td>
                    <td class='forumheader3'><input class='tbox' type='text' name='field4' value='"
                    .e107shop_get_gateway($_GET["g"], "field4")."'>
                    <input type='hidden' name='g' value='".$_GET["g"]."'></td>
                </tr>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_field."5</td>
                    <td class='forumheader3'><input class='tbox' type='text' name='field5' value='"
                    .e107shop_get_gateway($_GET["g"], "field5")."'>
                    <input type='hidden' name='g' value='".$_GET["g"]."'></td>
                </tr>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_field."6</td>
                    <td class='forumheader3'><input class='tbox' type='text' name='field6' value='"
                    .e107shop_get_gateway($_GET["g"], "field6")."'>
                    <input type='hidden' name='g' value='".$_GET["g"]."'></td>
                </tr>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_field."7</td>
                    <td class='forumheader3'><input class='tbox' type='text' name='field7' value='"
                    .e107shop_get_gateway($_GET["g"], "field7")."'>
                    <input type='hidden' name='g' value='".$_GET["g"]."'></td>
                </tr>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_field."8</td>
                    <td class='forumheader3'><input class='tbox' type='text' name='field8' value='"
                    .e107shop_get_gateway($_GET["g"], "field8")."'>
                    <input type='hidden' name='g' value='".$_GET["g"]."'></td>
                </tr>
                <tr>
                    <td class='forumheader2' width='20%'>".lan_admin_gateway_class."</td>
                    <td class='forumheader3'>
                        ".r_userclass("gateway_class", $gateway_class, "off", "public,guest,member,nobody,main,admin,classes")."
                    </td>
                </tr>
                <tr>
                    <td class='forumheader2' width='100%' colspan='2'><center>
                    <input type='submit' value='".lan_global_update."' name='subbed' class='tbox'></td>
                </tr>
                </table>
                </form>";

                $ns->tablerender("<center>".lan_admin_menu_gateway."</center>", $display);
}

require_once(e_ADMIN."footer.php");
